package edu.pku.sei.modeler.uml.internal;

import java.util.Iterator;
import java.util.Vector;

import edu.pku.sei.modeler.model.core.MetaModel;
import edu.pku.sei.modeler.model.uml.Kernel.Classifier;

public class UMLModel extends MetaModel {

	protected final Vector<Classifier> allUMLTypes = new Vector<Classifier>();
	
//	protected MetaTypedList umlPackages;

	public UMLModel() {
		setModel(this);
	}

	@Override
	public Vector getAllTypes() {
		return allUMLTypes;
	}

	@Override
	public String[] getTypeNames() {
		String[] typeNames = new String[allUMLTypes.size() + 1];
		Iterator it = allTypes.iterator();
		typeNames[0] = "";
		for (int i = 1; it.hasNext();) {
			Classifier type = (Classifier) it.next();
			typeNames[i++] = type.getName();
		}
		return typeNames;
	}

	@Override
	public boolean registerType(Object type) {
		if (type instanceof Classifier) {
			allUMLTypes.add((Classifier) type);
			return true;
		} else
			return false;
	}

	public Classifier getUMLTypeByName(String typeName) {
		Iterator it = allUMLTypes.iterator();
		for( ; it.hasNext(); ) {
			Classifier type = (Classifier)it.next();
			if(type.getName().equals(typeName))return type;
		}
		return null;
	}

//	@Override
//	public MetaTypedList getPackages() {
//		if(umlPackages == null) {
//			umlPackages = new MetaTypedSet(UMLPackage.class, this, ModelPackage.__UMLPACKAGE__);
//		}
//		return umlPackages;
//	}
	
	
	

}
